<?php

namespace app\api\logic;
use app\common\basics\Logic;
use app\service\TechnWeixinService;
use app\service\UserWeixinService;
use think\Db;


/**
 * 工作台统计
 * Class StatLogic
 * @package app\admin\logic\index
 */
class SendMu extends Logic
{
    public static function send_mu($openid,$order_id,$user_id){
        if(!empty($openid))
        {
            /////////////上方测试，下方正式/////////
            //查询订单详情
            $order_detail_title = Db::name('order_detail')->where(['order_id' => $order_id])->column('title');
            //  $order_detail_title = implode(',', $order_detail_title);
            $order_detail_title_new='服务项目:'.implode(',',$order_detail_title);
            //  foreach ($order_detail_title as $k=>$v){
            //      $order_detail_title_new.="\n ".($k+1).'.'.$v;
            //  }
            //查询下单人
            $order_address = Db::name('order_address')->where(['order_id' => $order_id])->find();
            $order_info = Db::name('order')->where('id',$order_id)->find();
            //查询用户
            $user_info = Db::name('user')->where(['id' => $user_id])->find();
            $tem_msg['touser'] = $openid;
            $tem_msg['template_id'] = 'RMv2u-c4hrBh6CLGZKhkPQ_aM0aIihfLwh6oOnDzJzs';
//            $tem_msg['miniprogram'] = [
//                'appid' => TechnWeixinService::$mini_appid,
//                'pagepath' => 'pages/order/orderdetail?order_id='.$order_id
//            ];


            if($order_info['budan_id']>0){
                $first='您好，有客户补单成功';
            }else{
                $first='您好，有客户下单成功';
            }

            $tem_msg['data'] = [
                'first' => [
                    'value' => $first,
                    'color' => '#173177'
                ],
                'keyword1' => [
                    'value' => $order_detail_title_new,
                    'color' => '#173177'
                ],
                'keyword2' => [
                    'value' => $order_address['name'],
                    'color' => '#173177'
                ],
                'keyword3' => [
                    'value' => substr_replace($order_address['mobile'], '****', 3, 4),
                    'color' => '#173177'
                ],
                'keyword4' => [
                    'value' => substr_replace($user_info['mobile'], '****', 3, 4),
                    'color' => '#173177'
                ],
                'keyword5' => [
                    'value' => $order_address['address'].$order_address['address_des'],
                    'color' => '#173177'
                ],
                'remark' => [
                    'value' => '请及时接单',
                    'color' => '#173177'
                ]
            ];

//            dump($tem_msg);die;

            UserWeixinService::send_wx_web_tem_msg($tem_msg);
        }

    }


}